from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier

# 加载数据集
iris = load_iris()
# 数据分割
x_train, x_test, y_train, y_test = train_test_split(iris['data'], iris['target'], test_size=0.2)
# 预处理
transfer = StandardScaler()
x_train = transfer.fit_transform(x_train)
x_test = transfer.fit_transform(x_test)

# 训练模型
mediator = KNeighborsClassifier()
mediator.fit(x_train, y_train)

y_pre = mediator.predict(x_test)
print(y_pre == y_test)
print(mediator.score(x_test, y_test))
